<?php
/**
 * 
 * Singleton base class
 * 
 * @category Framework
 * @package ROOT
 * @subpackage Base
 * @author Jiania J Hung <jiania@gmail.com
 * @copyright http://www.jiania.com
 * @since php5.2.x
 *  
 */


class Base {
	
	/**
	 * @var array list of namespaces currently in use
	 */
	private static $_usings = array ( );
	
	/**
	 * framework version identification - see compareVersion()
	 */
	const VERSION = '1.0';
	
	/**
	 * @return string the version of Prado framework
	 */
	public static function getVersion() {
		return self::VERSION;
	}
	/**
	 * Compare the specified Framework version string $version
	 * with the current Base::VERSION of the Zend Framework.
	 *
	 * @param  string  $version  A version string (e.g. "0.1").
	 * @return boolean           -1 if the $version is older,
	 *                           0 if they are the same,
	 *                           and +1 if $version is newer.
	 *
	 */
	final public static function compareVersion($version) {
		return version_compare ( $version, self::VERSION );
	}
	
	/**
	 * Class autoload loader.
	 * This method is provided to be invoked within an __autoload() magic method.
	 * @param string class name
	 */
	public static function autoload($className) {
		include_once ($className . php);
		if (! class_exists ( $className, false ) && ! interface_exists ( $className, false ))
			throw new Exception ( "Class file for '$className' cannot be found." );
	}
	
	/**
	 * @param integer the type of "powered logo". Valid values include 0 and 1.
	 * @return string a string that can be displayed on your Web page showing powered-by-PRADO information
	 */
	public static function poweredBy($logoType = 0) {
		$logoName = $logoType == 1 ? 'powered2' : 'powered';
		$url = 'http://www.jiania.com/images/' . $logoName . '.gif';
		return '<a title="Powered by Jiania" href="http://www.jiania.com/" target="_blank"><img src="' . $url . '" style="border-width:0px;" alt="Powered by Jiania" /></a>';
	}
	
	/**
	 * @return string the path of the framework
	 */
	public static function getFrameworkPath() {
		return ROOT_PATH;
	}
	
	/**
	 * Serializes a data.
	 * The original PHP serialize function has a bug that may not serialize
	 * properly an object.
	 * @param mixed data to be serialized
	 * @return string the serialized data
	 */
	public static function serialize($data) {
		$arr [0] = $data;
		return serialize ( $arr );
	}
	
	/**
	 * Unserializes a data.
	 * The original PHP unserialize function has a bug that may not unserialize
	 * properly an object.
	 * @param string data to be unserialized
	 * @return mixed unserialized data, null if unserialize failed
	 */
	public static function unserialize($str) {
		$arr = unserialize ( $str );
		return isset ( $arr [0] ) ? $arr [0] : null;
	}
	

}


